package org.dark.web;

import org.dark.web.scanner.TableScanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping(path = "/auto-gen")
public class AutoGenApi {


    private final GenericWebApi genericWebApi;


    @Autowired
    public AutoGenApi(GenericWebApi genericWebApi) {
        this.genericWebApi = genericWebApi;
    }
    @GetMapping("/{entity}/{id}")
    public Object getById(@PathVariable("entity") String entity, @PathVariable("id") String id) {
        return genericWebApi.getById(entity, id);
    }
    @GetMapping("/{entity}/all")
    public List<Object> getAll(@PathVariable("entity") String entity) {
        return genericWebApi.getAll(entity);
    }
    @DeleteMapping("/{entity}/{id}")
    public void deleteById(@PathVariable("entity") String entity, @PathVariable("id") String id) {
        genericWebApi.deleteById(entity, id);
    }
    @PostMapping("/{entity}")
    public int create(@PathVariable("entity") String entity, @RequestBody Object entityObject) {
        // Process the entityObject and save it
        return genericWebApi.save(entity, entityObject);
    }
    @PutMapping("/{entity}")
    public int updateById(@PathVariable("entity") String entity, @RequestBody Object entityObject) {
        // Process the entityObject and update the entity with the given id
        return genericWebApi.updateById(entity, entityObject);
    }

}
